//
//  schoolHomeTeacherTableViewCell.m
//  ioschishan
//
//  Created by 千翼网络科技 on 2017/8/1.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "schoolHomeTeacherTableViewCell.h"

@implementation schoolHomeTeacherTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:@"schoolHomeTeacherTableViewCell"]) {
        
        [self initView];
    }
    return self;
}

#pragma mark ---------------- init -----------------

- (void)initView{
    
    self.backgroundColor = getColor(@"ffffff");
    
    _leftImg = [[UIImageView alloc]init];
    _leftImg.image = [UIImage imageNamed:@"3479.jpg_wh1200"];
    _leftImg.layer.cornerRadius = screenScale(20);
    _leftImg.layer.masksToBounds = YES;
    [self addSubview:_leftImg];
    [_leftImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(screenScale(40));
        make.height.mas_equalTo(screenScale(40));
    }];
    
    _nameLable = [[UILabel alloc]init];
    _nameLable.text = @"七彩虹";
    _nameLable.numberOfLines = 1;
    _nameLable.textColor = getColor(@"333333");
    _nameLable.textAlignment = NSTextAlignmentLeft;
    _nameLable.font = get4sFont(12);
    [self addSubview:_nameLable];
    [_nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(19));
        make.left.mas_equalTo(self).with.offset(screenScale(65));
        
        
    }];
    
    _statusLable = [[UILabel alloc]init];
    _statusLable.text = @"七彩虹先生的个人简介";
    _statusLable.textColor = getColor(@"9b9b9b");
    _statusLable.textAlignment = NSTextAlignmentLeft;
    _statusLable.font = get4sFont(11);
    [self addSubview:_statusLable];
    [_statusLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(40));
        make.left.mas_equalTo(self).with.offset(screenScale(65));
        make.right.mas_equalTo(self).with.offset(screenScale(-80));
        
    }];
    
    _focusBtn = [ConfigXp buttonWithFrame:CGRectZero
                                             title:@"关注"
                                        titleColor:getColor(@"ff415e")
                                              font:get4sFont(11)
                                   backgroundColor:nil
                                             image:nil];
    [_focusBtn setTitle:@"已关注" forState:UIControlStateSelected];
    _focusBtn.layer.cornerRadius = screenScale(3);
    _focusBtn.layer.borderColor = getColor(@"ff415e").CGColor;
    _focusBtn.layer.borderWidth = screenScale(0.5);
    [_focusBtn addTarget:self action:@selector(focusBtnClcik) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_focusBtn];
    _focusBtn.center = self.center;
    [_focusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(screenScale(60));
        make.height.mas_equalTo(screenScale(24));
    }];
    
    _threadView = [[UIView alloc]init];
    _threadView.backgroundColor = getColor(@"eeeeee");
    [self addSubview:_threadView];
    [_threadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self).with.offset(0);
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(1));
    }];
}

- (void)focusBtnClcik{
    
    _focusBtn.selected = !_focusBtn.selected;

    NSLog(@"_index=%@,_teacherId=%@",_index,_teacherId);
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    
    NSMutableDictionary *productParams = [[NSMutableDictionary alloc]init];
    [productParams setValue: [PublicFunction getConfigWithKey:@"token"] forKey:@"token"];
    [productParams setValue: _teacherId forKey:@"passive_member_id"];
    
    [[MNetworkHandler sharedInstance]conURL:more_follow
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   
                                   if ([[returnData objectForKey:@"code"]intValue] == 1) {
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:1.0f];
                                       [hud removeFromSuperview];
                                       
                                   }else{
                                       
                                       [hud removeFromSuperview];
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:1.0f];
                                   }
                                   
                               } failureBlock:^(NSError *error) {
                                   
                                   [hud removeFromSuperview];
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                               }];
    
}

@end
